package org.jeecg.modules.demo.periodicwork.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.demo.Constants;
import org.jeecg.modules.demo.periodicwork.entity.CoopDeptSuper;
import org.jeecg.modules.demo.periodicwork.entity.PeriodicWorkCoopdept;
import org.jeecg.modules.demo.periodicwork.entity.TobedonePeriodicWork;
import org.jeecg.modules.demo.periodicwork.mapper.PeriodicWorkCoopdeptMapper;
import org.jeecg.modules.demo.periodicwork.mapper.PeriodicWorkMapper;
import org.jeecg.modules.demo.periodicwork.mapper.tobedonePeriodicWorkMapper;
import org.jeecg.modules.demo.periodicwork.service.ITobedonePeriodicWorkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TobedonePeriodicWorkServiceImpl extends ServiceImpl<tobedonePeriodicWorkMapper, TobedonePeriodicWork> implements ITobedonePeriodicWorkService {
    @Autowired
    private  tobedonePeriodicWorkMapper tobedonePeriodicWorkMapper;
    @Autowired
    private PeriodicWorkCoopdeptMapper PeriodicWorkCoopdeptMapper;
    @Override
    public List<TobedonePeriodicWork> SelectTobedonePeriodicWorkListByOrgId(String orgId, String status) {
        return tobedonePeriodicWorkMapper.SelectTobedonePeriodicWorkListByOrgId(orgId,status);
    }

    @Override
    public void saveMain(TobedonePeriodicWork tobedonePeriodicWork, List<PeriodicWorkCoopdept> periodicWorkCoopdeptList) {
        tobedonePeriodicWorkMapper.insertToPeriodicWork(tobedonePeriodicWork);
        if(periodicWorkCoopdeptList!=null && periodicWorkCoopdeptList.size()>0) {
            for(PeriodicWorkCoopdept entity:periodicWorkCoopdeptList) {
                //外键设置
                entity.setMainId(tobedonePeriodicWork.getId());
                entity.setCoopDepartTaskstatus(Constants.TODO);
                PeriodicWorkCoopdeptMapper.insert(entity);
            }
        }
    }

    @Override
    public List<CoopDeptSuper> SelectCoopDeptSuper(String orgId) {
        return tobedonePeriodicWorkMapper.SelectCoopDeptSuper(orgId);
    }
}
